﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    public class S_ChatPacket : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_ChatPacket ).FullName );

        private byte[] _byte = null;

        public S_ChatPacket( L1PcInstance pc, String chat, int opcode, int type )
        {
            if ( type == 0 )
            { // 通常チャット
                writeC( opcode );
                writeC( type );
                if ( pc.isInvisble() )
                {
                    writeD( 0 );
                }
                else
                {
                    writeD( pc.getId() );
                }
                writeS( pc.getName() + ": " + chat );
            }
            else if ( type == 2 )
            { // 叫び
                writeC( opcode );
                writeC( type );
                if ( pc.isInvisble() )
                {
                    writeD( 0 );
                }
                else
                {
                    writeD( pc.getId() );
                }
                writeS( "<" + pc.getName() + "> " + chat );
                writeH( pc.getX() );
                writeH( pc.getY() );
            }
            else if ( type == 3 )
            { // 全体チャット
                writeC( opcode );
                writeC( type );
                if ( pc.isGm() == true )
                {
                    writeS( "[******] " + chat );
                }
                else
                {
                    writeS( "[" + pc.getName() + "] " + chat );
                }
            }
            else if ( type == 4 )
            { // 血盟チャット
                writeC( opcode );
                writeC( type );
                writeS( "{" + pc.getName() + "} " + chat );
            }
            else if ( type == 9 )
            { // ウィスパー
                writeC( opcode );
                writeC( type );
                writeS( "-> (" + pc.getName() + ") " + chat );
            }
            else if ( type == 11 )
            { // パーティーチャット
                writeC( opcode );
                writeC( type );
                writeS( "(" + pc.getName() + ") " + chat );
            }
            else if ( type == 12 )
            { // トレードチャット
                writeC( opcode );
                writeC( type );
                writeS( "[" + pc.getName() + "] " + chat );
            }
            else if ( type == 13 )
            { // 連合チャット
                writeC( opcode );
                writeC( type );
                writeS( "{{" + pc.getName() + "}} " + chat );
            }
            else if ( type == 14 )
            { // チャットパーティー
                writeC( opcode );
                writeC( type );
                if ( pc.isInvisble() )
                {
                    writeD( 0 );
                }
                else
                {
                    writeD( pc.getId() );
                }
                writeS( "(" + pc.getName() + ") " + chat );
            }
            else if ( type == 16 )
            { // ウィスパー
                writeC( opcode );
                writeS( pc.getName() );
                writeS( chat );
            }
        }

        override
        public byte[] getContent()
        {
            if ( null == _byte )
            {
                _byte = getBytes(); ;//_bao.toByteArray();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_ChatPacket";
        }
    }
}
